package com.lc.pianostudent.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;


import com.lc.pianostudent.R;
import com.lc.pianostudent.adapter.ContactDetailAdapter;
import com.lc.pianostudent.bean.ContactDetailBean;
import com.lc.pianostudent.bean.GetStudyPictureBean;
import com.lc.pianostudent.conn.PostMailGetstudy;
import com.lc.pianostudent.view.ScrollLinearLayoutManager;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/7/2.
 */

public class TeacherDetailActivity extends BaseActivity{

    private List<GetStudyPictureBean> contactDetailList = new ArrayList<>();


    @BoundView(R.id.contact_detail_recycle_view) private RecyclerView recyclerView;
    private ContactDetailAdapter contactDetailAdapter;
    private PostMailGetstudy.PostMailGetstudyInfo curretInfo;
    @BoundView(R.id.js_banner_detail) private ImageView js_banner;

    public PostMailGetstudy postMailGetstudy = new PostMailGetstudy(new AsyCallBack<PostMailGetstudy.PostMailGetstudyInfo>(){

        @Override
        public void onSuccess(String toast, int type, Object o, PostMailGetstudy.PostMailGetstudyInfo postMailGetstudyInfo) throws Exception {
            curretInfo = postMailGetstudyInfo;
            GlideLoader.getInstance().get(postMailGetstudyInfo.data,js_banner,R.mipmap.js_banner);

            contactDetailList.addAll(postMailGetstudyInfo.contactDetailList);
            contactDetailAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String toast, int type) throws Exception {
            UtilToast.show(toast);
        }
    });
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_teacher_detail);
        setBackTrue();

        iniView();
    }

    private void iniView(){
        setTitleName("详细资料");


        ScrollLinearLayoutManager scrollLinearLayoutManager = new ScrollLinearLayoutManager(this);
        recyclerView.setLayoutManager(scrollLinearLayoutManager);
        recyclerView.setHasFixedSize(true);
        recyclerView.setNestedScrollingEnabled(false);
        contactDetailAdapter = new ContactDetailAdapter(this, contactDetailList);
        recyclerView.setAdapter(contactDetailAdapter);
        postMailGetstudy.id = getIntent().getStringExtra("id");
        postMailGetstudy.type = getIntent().getStringExtra("type");
        postMailGetstudy.execute();


        contactDetailAdapter.setOnItemClickListener(new ContactDetailAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                startActivity(new Intent(TeacherDetailActivity.this,ContactDetailItemActivity.class)
                        .putExtra("id",curretInfo.contactDetailList.get(position).getId()).putExtra("user_id",getIntent().getStringExtra("id")));
            }
        });
    }
}
